<template>
	<section>
		<!--工具条-->

		<el-row class="toolbar" style="padding-bottom: 0px;" type="flex" >
			<el-col :span="6">
				<el-button type="primary" size="medium" @click="handleAdd">新增画室</el-button>
			</el-col>
			<el-col :span="18"  style="float:right">
				<el-form :inline="true" :model="filters" style="float:right">
	
					<el-form-item >
						<el-select v-model="selections.studios" style="width:140px;" placeholder="选择画室" size="medium">
						<el-option v-for="studio in studios"
										:key="studio.studioName"
										:value="studio.studioName">
								</el-option>
						</el-select>
					</el-form-item>
					<el-form-item >
						<el-select v-model="selections.provinces" style="width:140px;" placeholder="选择省份" size="medium">
								<template v-for="(item,idx) in hasProvinces"  >
										<el-option :key="idx" :label="item.province" :value="item.province"></el-option>
								</template>
						</el-select>
					</el-form-item>
					<el-form-item>
						<el-button type="primary" v-on:click="getUsers" size="medium">查询</el-button>
					</el-form-item>
				</el-form>
			</el-col>
		</el-row>
		
		<!--列表-->
		<el-table  :data="users" highlight-current-row v-loading="listLoading" @selection-change="selsChange" border 
		:header-cell-style="{background:'#204BD6',color:'#fff'}"
		style="width: 100%;" >
			<el-table-column v-for="(listData, index) in list" :prop=listData.prpo :label=listData.label :width=listData.width header-align='center' align='center' sortable>
			</el-table-column>
			<!--<el-table-column prop="studioName" label="画室名称" header-align='center' sortable>
			</el-table-column>
			<el-table-column prop="studioAreaCode" label="画室地区" width="140" header-align='center' sortable>
			</el-table-column>
			<el-table-column prop="studentsCount" label="考生人数" width="110" header-align='center' sortable>
			</el-table-column>
			<el-table-column prop="contactName" label="联系老师" width="120" header-align='center' align='center' sortable>
			</el-table-column>
			<el-table-column prop="contactMobile" label="联系电话" width="150" header-align='center' align='center' sortable>
			</el-table-column>
			<el-table-column prop="contactEmail" label="email" width="200" header-align='center' sortable>
			</el-table-column>-->
			<el-table-column label="操作" width="150" header-align='center'>
				<template scope="scope">
					<el-button type="text" size="small" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
					<el-button type="text" size="small" @click="handleQuery(scope.$index, scope.row)">查询</el-button>
					<el-button type="text" size="small" @click="handleValid(scope.$index, scope.row)">{{scope.row.activityStatus===0?"启用":"禁用"}}</el-button>
				</template>
			</el-table-column>
		</el-table>

		<!--工具条-->
		<el-col :span="24" class="toolbar" >
			<!-- <el-button type="danger" @click="batchRemove" :disabled="this.sels.length===0">批量删除</el-button> -->
			<el-pagination layout="prev, pager, next" @current-change="handleCurrentChange" :page-size="20" :total="total" center >
			</el-pagination>
		</el-col>

		<!--编辑界面-->
		<el-dialog title="修改画室" :visible.sync="editFormVisible" :close-on-click-modal="false" width="800" >
			<studioModify :studio='editForm'></studioModify>
		</el-dialog>

		<!--新增界面-->
		<el-dialog title="新增画室" :visible.sync="addFormVisible" :close-on-click-modal="false" width="800"  >
			<studioAdd ></studioAdd>
		</el-dialog>
	</section>
</template>

<script>
	import util from '../../common/js/util'
	import provinceCodeList from "../../utils/provinceCode";
	import { getUserListPage,  getStudioList,studio_listStudio } from '../../api/api';

	import studioModify from './studioModify'
	import studioAdd from './studioAdd'
	export default {
		components:{studioAdd,studioModify},
		data() {
			return {
				studios:[],
				filters: {
					name: ''
				},
        //列表循环
        list:[
          {prpo:'studioName',label:'序号',width:'110'},
          {prpo:'studioCode',label:'画室名称',width:''},
          {prpo:'studioAreaCode',label:'画室地区',width:'140'},
          {prpo:'studentsCount',label:'考生人数',width:'110'},
          {prpo:'contactName',label:'联系老师',width:'160'},
          {prpo:'contactMobile',label:'联系电话',width:'120'},
          {prpo:'contactEmail',label:'email',width:'200'},
        ],
				users: [],
				total: 0,
				page: 1,
				listLoading: false,
				sels: [],//列表选中列
				selections:{
					provinces:'',//选择省份
					studios:'',//选择省份
				},
				hasProvinces:provinceCodeList,
				hasStudios:[{lable:'白鹭'},{lable:'飞音'},{lable:'跑费'}],
				editFormVisible: false,//编辑界面是否显示
				editLoading: false,
				editFormRules: {
					name: [
						{ required: true, message: '请输入姓名', trigger: 'blur' }
					]
				},
				//编辑界面数据
				editForm: {
					id: 0,//画室ID
					studioname: 'xxx画室',//画室名称
					provice: '上海',//hua
					person:"老师A",
					phone: '',
					email: ''
				},

				addFormVisible: false,//新增界面是否显示
				addLoading: false,
				addFormRules: {
					name: [
						{ required: true, message: '请输入姓名', trigger: 'blur' }
					]
				},
				//新增界面数据
				forms: {
					size:10,
					current: 1,
					studioAreaCode: "",
					studioName: '',

				},

			}
		},
		methods: {
	
			handleCurrentChange(val) {
				this.page = val;
				this.getUsers();
			},
			//获取用户列表
			getUsers() {
				this.listLoading = true;
				studio_listStudio(this.forms).then((res) => {
					console.log(res)
					this.total = res.result.total;
					this.users = res.result.records;
					this.users.sort((a,b)=>{return  a.studioCode>b.studioCode})
					this.listLoading = false;
				});
			},
			//删除
			handleQuery: function (index, row) {
				this.$store.state.studio.name=row.studioname
				this.$store.state.studio.studentsCount=row.studentsCount
				this.$router.push({path: '/studioDetail'})
			
			},
			//显示编辑界面
			handleEdit: function (index, row) {
				this.editFormVisible = true;
				this.editForm = Object.assign({}, row);
			},
			//显示新增界面
			handleAdd: function () {
				this.addFormVisible = true;
			},
			//编辑
			
			//新增
			addSubmit: function () {
				this.$refs.addForm.validate((valid) => {
					if (valid) {
						this.$confirm('确认提交吗？', '提示', {}).then(() => {
							this.addLoading = true;
							let para = Object.assign({}, this.addForm);
							para.birth = (!para.birth || para.birth == '') ? '' : util.formatDate.format(new Date(para.birth), 'yyyy-MM-dd');
							addUser(para).then((res) => {
								this.addLoading = false;
								this.$message({
									message: '提交成功',
									type: 'success'
								});
								this.$refs['addForm'].resetFields();
								this.addFormVisible = false;
								this.getUsers();
							});
						});
					}
				});
			},
			selsChange: function (sels) {
				this.sels = sels;
			},
		},
		mounted() {
			getStudioList().then((res)=>{this.studios=res})
			this.getUsers();
		}
	}

</script>

<style scoped>
.el-button--small{
	padding: 1px 1px;
}
.el-dialog__header{
	text-align: center;
}
.el-dialog__title{
	font-size: 32px;
}
.el-pagination {
  margin: 20px;
  font-weight: 700;
  text-align: center;
}
</style>